package org.grapes.wine.api.server.method.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.grapes.wine.api.bean.GetPath2BYDRouteBean;
import org.grapes.wine.api.bean.MethodBean;
import org.grapes.wine.api.bean.ObjectFactory;
import org.grapes.wine.api.method.EWineMethod;
import org.grapes.wine.api.server.method.handler.RenderDocument;
import org.grapes.wine.api.server.model.DAOName;
import org.grapes.wine.api.server.model.dao.Path2BYDDAO;
import org.grapes.wine.api.server.persistence.DAOOperate;
import org.w3c.dom.Document;

public class GetPath2BYDRoute extends RenderDocument {
	static Logger logger = Logger.getLogger(GetPath2BYDRoute.class);
	private static List param = new ArrayList();
	static {
		param.add("start");
	}

	public Document execute(HttpServletRequest request) throws Exception {
		boolean paramMatch = false;
		
		String start = request.getParameter("start");
		Path2BYDDAO path2BYDDAO = null;

		List list = DAOOperate.queryList(DAOName.Path2BYD);

		for (Iterator it = list.iterator(); it.hasNext();) {
			path2BYDDAO = (Path2BYDDAO) it.next();
			if (path2BYDDAO.getStart().equals(start)) {
				paramMatch = true;
				break;
			}
		}
		
		if (paramMatch) {
			// put data input bean
			ObjectFactory factory = new ObjectFactory();
			GetPath2BYDRouteBean bean = factory.createGetPath2BYDRouteBean();
			bean.setRoute(path2BYDDAO.getPath());
			MethodBean methodBean = new MethodBean();
			methodBean.setBean(bean);
			methodBean.setClazz(GetPath2BYDRouteBean.class);
			return initDocumentByJAXB(methodBean);
		}
		return null;
	}

	public EWineMethod getMethodName() {
		return EWineMethod.GET_PATH2BYD_ROUTE;
	}

	public List getParam() {
		return param;
	}

}
